//
//  YGSelectView.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/3/31.
//

#import "YGSelectView.h"
#import "YGSelectItemView.h"
@interface YGSelectView ()<YGSelectItemViewDelegate>

@property (nonatomic, strong) YGSelectItemView *itemView;

@end
@implementation YGSelectView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView{
    UIView *bgView = [[UIView alloc] initWithFrame:self.bounds];
    bgView.backgroundColor = UIColorFromRGBAlpha(0x333333, 0.5);
    bgView.userInteractionEnabled = YES;
    [self addSubview:bgView];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickBGViewAction)];
    [bgView addGestureRecognizer:tap];
    [self addSubview:bgView];
    
    [self addSubview:self.itemView];

}

- (void)clickBGViewAction{
    [self hidden];
}


- (void)configureData:(NSArray *)datas{
    [self.itemView cnofigureData:datas];
}

- (void)show{
    self.hidden = NO;
    [self.itemView show];
}


- (void)hidden{
    [self.itemView hidden];
    WeakSelf(self);
    [self.itemView setHiddenSuBlock:^{
        weakself.hidden = YES;
    }];
}

- (void)selectViewWithIndex:(NSInteger)index selectView:(YGSelectItemView *)selectView{
    if ([self.delegate respondsToSelector:@selector(selectViewWithIndex:selectView:)]) {
        [self.delegate selectViewWithIndex:index selectView:self];
    }
    [self hidden];
}

- (YGSelectItemView *)itemView{
    if (!_itemView) {
        _itemView = [[YGSelectItemView alloc] initWithFrame:CGRectMake(0, 0, self.width, 0)];
        _itemView.delegate = self;
    }
    return _itemView;
}
   
@end
